﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MobileShop.Controls;
using POSSystem.BLL;

namespace MobileShop
{
    public partial class TransactionHistory : BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (SessionUser == null || SessionUser.RowCount == 0)
                this.Response.Redirect("Login.aspx?url=MyAccount.aspx");
            if (!IsPostBack)
            {
                rpt.Rebind();
                PageMap = string.Format("My Account[{0}]|Transaction History[{1}]", this.ResolveUrl("~/MyAccount.aspx"), this.ResolveUrl("~/TransactionHistory.aspx"));
            }
        }

        protected void dataPager_OnPageIndexChanged(object sender, PageIndexChangedEventArgs e)
        {
            rpt.Rebind();
        }

        protected void rpt_OnNeedDataSource(object sender, EventArgs e)
        {
            View_CustomerOrders orders = new View_CustomerOrders();
            int count = orders.Search(View_CustomerOrders.ColumnNames.StatusID + "!=" + OrderStatus.Temporary.ToString() + " and " + View_CustomerOrders.ColumnNames.CustomerID + " = " + View_Customers.GetCurrentUser().s_ID,
                View_CustomerOrders.ColumnNames.ID + " desc", dataPagerDown.CurrentPageIndex * dataPagerDown.PageSize, dataPagerDown.PageSize);
            rpt.DataSource = orders.DefaultView;
            dataPagerDown.TotalItems = count;
        }
    }
}